日期与时间戳的转换,处理后台传的时间,捕获今天昨天的日期

您所在的位置:网站首页 unix时间戳 换算 日期与时间戳的转换,处理后台传的时间,捕获今天昨天的日期

日期与时间戳的转换,处理后台传的时间,捕获今天昨天的日期

2023-07-10 21:13| 来源: 网络整理| 查看: 265

日期转时间戳 // 日期转时间戳 function timechange(t) { let date = new Date(t) let time = (date.getTime())/1000 return time }

时间戳转日期 // 时间戳转日期 function changetime(time) { time = parseFloat('' + time); let currentData = new Date(); let date = new Date(time); let y = date.getFullYear(); let month = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1); let d = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); let h = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); let m = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); let s = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); return y + "-" + month + "-" + d; } ​

将后台传过来的时间进行转换(往后+8小时)

即数据库操作时间类型为:datetime 类型

前端接收到的参数为2022-03-18T01:46:08.000+00:00 这种加了时区的格式

这个格式的数据转换成前端可以展示的数据时,得往后+8小时(如果后台传过来的时间比数据库的早八个小时)

// 将后台传过来的时间进行转换(往后+8小时) function resolvingDate(date){ var d = new Date(date); var month = (d.getMonth() + 1) < 10 ? '0'+(d.getMonth() + 1) : (d.getMonth() + 1); var day = d.getDate()


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3